/*
 * HttpHelper.h
 *
 *  Created on: 23.9.2011
 *      Author: lis1
 */

#ifndef HTTPHELPER_H_
#define HTTPHELPER_H_

#include <string>

using namespace std;


//GET / HTTP/1.1
//User-Agent: nmps-radio-streamer
//Host: www.shoutcast.com
//Accept: */*

// data structure representing an HTTP request
// we'll only capture the most important information

struct HttpRequest {
	string remoteHostName; // the name of remote host, www.shoutcast.com for example
	int remoteHostPort; // default to 80
	string URI; //Requested URI (or just '/' as the default?)
//	char * userAgent;
//	char * Accept; // I assume we'll accept everything!
};

// data structure representing an HTTP response (non streaming version)
struct HttpResponse {
	char * data;
};


class HttpHelper {
public:
	HttpHelper();

	virtual ~HttpHelper();

	static void retrieveURIContent(HttpRequest request, HttpResponse & response);

	//given an HTTP URL, extract the host part
	static string extractHost(string url);

	//given an HTTP URL, extract the port
	static int extractPort(string url);

	//given an HTTP URL, extract the resource path part from this URL
	static string extractPath(string url);

	static int create_tcp_socket();

	static string createHttpRequestStr(HttpRequest httpRequest, bool useIcyMeta = false);

	//extract the icy-metaint header value from the http response headers
	static int extractIcyMetaInt(char * httpResponseHeaders);
};


#endif /* HTTPHELPER_H_ */
